#include<iostream>
#include<cmath>
using namespace std;
int f(int m);
int main()
{
    int n;
    while(cin>>n)
    {
       if(n==0) break;
       int count=0,sum;
       for(int i=2;i<=n;i++)
       {
          sum=0;
          for(int j=i;j<=n;j++)
          {
             if(f(j)) {sum+=j;if(sum==n) {count++;break;} if(sum>n) break;} 
          }
       }
       cout<<count<<endl;
    }
    system("pause");
    return 0;
}

int f(int m)
{if(m==1) return 0;
 int j=2;
 double k=sqrt(double(m));
 while(m%j!=0&&j<=k)
    j++;
 if(j>k)   return 1;
 else      return 0;
} 
